﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using Brush=System.Windows.Media.Brush;
using Color=System.Windows.Media.Color;

#endregion

namespace ScrumTable.UI.View.Converter
{

    /// <summary>
    /// convert a priority (int value) into a brush
    /// </summary>
    [ValueConversion(typeof(int), typeof(Brush))]
    public class ConverterPriorityBrush : IValueConverter
    {

        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------
        /// <summary>
        /// int -> brush
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>
        /// A converted value. If the method returns null, the valid null value is used.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string) value = int.Parse(value as string, CultureInfo.InvariantCulture);
            if (!(value is int)) return new SolidColorBrush(Colors.White);

            var priority = (int)value;

            switch (priority)
            {

                    /*
        case 1:
            return new SolidColorBrush(Color.FromRgb(255, 153, 153));
        case 2:
            return new SolidColorBrush(Color.FromRgb(255, 193, 153));
        case 3:
            return new SolidColorBrush(Color.FromRgb(255, 238, 153));
        case 4:
            return new SolidColorBrush(Color.FromRgb(226, 255, 153));
        default:
            return new SolidColorBrush(Colors.White);
                 */


                case 1:
                    return Application.Current.Resources["TaskRed"];
                case 2:
                    return Application.Current.Resources["TaskOrange"];
                case 3:
                    return Application.Current.Resources["TaskYellow"];
                case 4:
                    return Application.Current.Resources["TaskGreen"];
                default:
                    return Application.Current.Resources["TaskWhite"];

            }
        }

        /// <summary>
        /// Not supported. Throws NotSupportedException.
        /// </summary>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
        
       

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion


    }
}
